//
//  LYQMineIntegralCell.m
//  ZCProject
//
//  Created by Zheng on 16/12/6.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQMineIntegralCell.h"

@implementation LYQMineIntegralCell

- (instancetype)initWithCellStyle:(LYQMineIntegralCellStyle)cellStyle {
    
    _cellStyle = cellStyle;
    
    NSString *identitier = @"";
    if (cellStyle == LYQMineIntegralCellIntegralStyle) {
        identitier = kLYQMineIntegralCell_ID;
    } else {
        identitier = kLYQMineAllowanceCell_ID;
    }
    
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identitier];
    
    if (self == nil) {
        return nil;
    }
    
    if (cellStyle == LYQMineIntegralCellIntegralStyle) {
        
        [self.contentView addSubview:self.value1Lbl];
        [self.contentView addSubview:self.value2Lbl];
        [self.contentView addSubview:self.value3Lbl];
        [self.contentView addSubview:self.line2View];
        [self.contentView addSubview:self.line1View];
        
        [self layoutSubviewsInContentView];
        
    } else {
        
        [self.contentView addSubview:self.titleLbl];
        [self.contentView addSubview:self.valueLbl];
    
        [self layoutSubviewsInContentView];
    }
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return self;
}

#pragma mark - layout subviews
- (void)layoutSubviewsInContentView {
    
    if (_cellStyle == LYQMineIntegralCellIntegralStyle) {
        
        [_value3Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.right.equalTo(self);
            make.width.equalTo(@(kWScale(100)));
        }];
        
        [_line2View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(kWScale(0.5)));
            make.right.equalTo(_value3Lbl.mas_left);
            make.top.bottom.equalTo(self);
        }];
        
        [_value2Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.width.equalTo(_value3Lbl);
            make.right.equalTo(_line2View.mas_left);
        }];
        
        [_line1View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(kWScale(0.5)));
            make.top.bottom.equalTo(self);
            make.right.equalTo(_value2Lbl.mas_left);
        }];
        
        [_value1Lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_line1View.mas_left);
            make.centerY.equalTo(self);
            make.left.equalTo(@(kWScale(14)));
        }];
        
    } else {
    
        [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kWScale(14));
            make.centerY.equalTo(self);
            make.right.equalTo(self.mas_centerX);
        }];
        
        [_valueLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_titleLbl.mas_right).offset(kWScale(40));
            make.centerY.right.equalTo(self);
        }];
    }
    
    
}

#pragma mark - load subviews
- (UILabel *)value1Lbl {
    if (_value1Lbl) {
        return _value1Lbl;
    }
    
    _value1Lbl = [[UILabel alloc] init];
    _value1Lbl.font = kWFont(15);
    _value1Lbl.textColor = kHexadecimal(@"666666");
    
    return _value1Lbl;
}

- (UILabel *)value2Lbl {
    if (_value2Lbl) {
        return _value2Lbl;
    }
    
    _value2Lbl = [[UILabel alloc] init];
    _value2Lbl.font = kWFont(15);
    _value2Lbl.textColor = kHexadecimal(@"666666");
    _value2Lbl.textAlignment = NSTextAlignmentCenter;

    return _value2Lbl;
}

- (UILabel *)value3Lbl {
    if (_value3Lbl) {
        return _value3Lbl;
    }
    
    _value3Lbl = [[UILabel alloc] init];
    _value3Lbl.font = kWFont(15);
    _value3Lbl.textColor = kHexadecimal(@"666666");
    _value3Lbl.textAlignment = NSTextAlignmentCenter;

    return _value3Lbl;
}

- (UIView *)line1View {
    if (_line1View) {
        return _line1View;
    }
    
    _line1View = [[UIView alloc] init];
    _line1View.backgroundColor = RGB(200, 199, 204, 1);
    
    return _line1View;
}

- (UIView *)line2View {
    if (_line2View) {
        return _line2View;
    }
    
    _line2View = [[UIView alloc] init];
    _line2View.backgroundColor = RGB(200, 199, 204, 1);
    
    return _line2View;
}

- (UILabel *)titleLbl {
    if (_titleLbl) {
        return _titleLbl;
    }
    
    _titleLbl = [[UILabel alloc] init];
    _titleLbl.font = kWFont(15);
    _titleLbl.textColor = kHexadecimal(@"666666");
    
    return _titleLbl;
}

- (UILabel *)valueLbl {
    if (_valueLbl) {
        return _valueLbl;
    }
    
    _valueLbl = [[UILabel alloc] init];
    _valueLbl.font = kWFont(15);
    _valueLbl.textColor = kHexadecimal(@"666666");
    
    return _valueLbl;
}

@end
